import { createApp } from 'vue'
import ElementPlus from 'element-plus'   // 导入ElementPlus组件
import 'element-plus/dist/index.css'
import router from "./router/router.js";  // 路由
import App from "./App.vue";
import * as ElementPlusIconsVue from '@element-plus/icons-vue'  // 图标
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import {doGet} from "./http/httpRequest.js";  // 国际化

let app =createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

/**
 * 自定义指令根据权限是否删除按钮
 */
app.directive('hasPermission', (el, binding) => {
    doGet('/api/login/info',{}).then(resp=>{
        let user = resp.data.data;
        let permissionList = user.permissionList;

        let flag=false;
        for (let key in permissionList){
            if (permissionList[key]===binding.value){
                flag=true;
                break;
            }
        }
        if (!flag){
            // el.style.display='none'
            el.parentNode && el.parentNode.replaceChildren(el)
        }
    })
})
app.use(ElementPlus,{locale: zhCn,}).use(router).mount('#app')

